/**
 * Copyright (C) T-Systems International, 2013-2014
 *
 * The copyright of the computer program herein is the property of
 * T-Systems International. The program may be used and/or copied
 * only with the written permission of T-Systems International or in
 * accordance with the terms and conditions stipulated in the
 * agreement/contract under which the program has been supplied.
 *
 * $Author$
 * $Date$
 * $Rev$
 */
package com.tsystems.migdb.sftp.server;

import lombok.NonNull;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class MigdbFileSystemFactory extends VirtualFileSystemFactory {

    private final Path serverRoot;

    public MigdbFileSystemFactory(@NonNull String serverRoot) {
        super(serverRoot);
        Path path = FileSystems.getDefault().getPath(serverRoot);
        if (!Files.isDirectory(path)) {
            throw new IllegalArgumentException("serverRoot must point to a directory");
        }
        this.serverRoot = path;
    }

    @Override
    protected String computeRootDir(String userName) {
        Path userDir = FileSystems.getDefault().getPath(serverRoot.toString(), userName);
        return userDir.toString();
    }

}